// pages/contact/contact.js
Page({
  data: {
    isLogin: false,
    formInfo: {},
    submissions: [] // 新增：用于存储所有提交的表单数据
  },

  onLoad: function() {
    this.checkLoginStatus();
  },

  onShow: function() {
    this.checkLoginStatus();
  },

  checkLoginStatus: function() {
    const token = wx.getStorageSync('token');
    this.setData({ isLogin: !!token });
  },

  navigateToLogin: function() {
    wx.navigateTo({
      url: '/pages/login/login'
    });
  },

  handleLogout: function() {
    wx.removeStorageSync('token');
    this.setData({ isLogin: false });
    wx.showToast({
      title: '已退出登录',
      icon: 'success'
    });
  },

  formSubmit: function(e) {
    if (!this.data.isLogin) {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      });
      return;
    }

    const formInfo = e.detail.value;
    // 将当前提交的信息添加到submissions数组中
    const newSubmissions = this.data.submissions.concat([formInfo]);
    this.setData({ submissions: newSubmissions });

    wx.showToast({
      title: '提交成功',
      icon: 'success'
    });
  },

  handleLogout: function() {
    wx.removeStorageSync('token');
    this.setData({ isLogin: false, submissions: [] }); // 清空提交记录
    wx.showToast({
      title: '已退出登录',
      icon: 'success'
    });
  }
});